About John D. Cook

I have decades of consulting experience helping companies solve complex problems involving applied math, statistics, and data privacy.

The RSS's url is : https://www.johndcook.com/blog/feed/

Please copy to your reader or subscribe it with :

Preview of RSS feed of John D. Cook

Numerical application of mean value theorem

2024-05-08 02:07:28

Suppose you’d like to evaluate the function for small values of z, say z = 10−8. This example comes from [1]. The Python code from numpy import exp def f(z): return (exp(z) - 1 - z)/z**2 print(f(1e-8)) prints -0.607747099184471. Now suppose you suspect numerical difficulties and compute your result to 50 decimal places using bc […]

The post Numerical application of mean value theorem first appeared on John D. Cook.

Numerical differentiation with a complex step

2024-05-07 21:34:35

The most obvious way to approximate the derivative of a function numerically is to use the definition of derivative and stick in a small value of the step size h. f′ (x) ≈ ( f(x + h) − f(x) ) / h. How small should h be? Since the exact value of the derivative is the […]

The post Numerical differentiation with a complex step first appeared on John D. Cook.

MCMC and the coupon collector problem

2024-05-07 08:20:18

Bob Carpenter wrote today about how Markov chains cannot thoroughly cover high-dimensional spaces, and that they do not need to. That’s kinda the point of Monte Carlo integration. If you want systematic coverage, you can/must sample systematically, and that’s impractical in high dimensions. Bob gives the example that if you want to get one integration […]

The post MCMC and the coupon collector problem first appeared on John D. Cook.

Up and down the abstraction ladder

2024-05-04 20:58:00

It’s easier to go up a ladder than to come down, literally and metaphorically. Gian-Carlo Rota made a profound observation on the application of theory. One frequently notices, however, a wide gap between the bare statement of a principle and the skill required in recognizing that it applies to a particular problem. This isn’t quite […]

The post Up and down the abstraction ladder first appeared on John D. Cook.

Making documents with makefiles

2024-05-02 00:36:52

I learned to use the command line utility make in the context of building C programs. The program make reads an input file to tell it how to make things. To make a C program, you compile the source files into object files, then link the object files together. You can tell make what depends […]

The post Making documents with makefiles first appeared on John D. Cook.

Applied abstraction

2024-05-01 21:21:08

“Good general theory does not search for the maximum generality, but for the right generality.” — Saunders Mac Lane   One of the benefits of a scripting language like Python is that it gives you generalizations for free. For example, take the function sorted. If you give it a list of integers, it will return […]

The post Applied abstraction first appeared on John D. Cook.

A deck of cards

2024-04-30 21:16:39

One time when I was in grad school, I was a teaching assistant for a business math class that included calculus and a smattering of other topics, including a little bit of probability. I made up examples involving a deck of cards, but then learned to my surprise that not everyone was familiar with playing […]

The post A deck of cards first appeared on John D. Cook.

What can JWST see?

2024-04-28 21:02:08

The other day I ran across this photo of Saturn’s moon Titan taken by the James Webb Space Telescope (JWST). If JWST can see Titan with this kind of resolution, how well could it see Pluto or other planets? In this post I’ll do some back-of-the-envelope calculations, only considering the apparent size of objects, ignoring […]

The post What can JWST see? first appeared on John D. Cook.

Fizz buzz walk

2024-04-27 20:57:30

I ran across a graphic yesterday made by taking a sequence of steps of the same length, turning left on the nth step if n is prime, and otherwise continuing in the same direction. Here’s my recreation of the first 1000 steps: You can see that in general it makes a lot of turns at […]

The post Fizz buzz walk first appeared on John D. Cook.

Closed-form solutions to nonlinear PDEs

2024-04-25 19:21:38

The traditional approach to teaching differential equations is to present a collection of techniques for finding closed-form solutions to ordinary differential equations (ODEs). These techniques seem completely unrelated [1] and have arcane names such as integrating factors, exact equations, variation of parameters, etc. Students may reasonably come away from an introductory course with the false […]

The post Closed-form solutions to nonlinear PDEs first appeared on John D. Cook.

Choosing a Computer Language for a Project

2024-04-24 08:19:22

Julia. Scala. Lua. TypeScript. Haskell. Go. Dart. Various computer languages new and old are sometimes proposed as better alternatives to mainstream languages. But compared to mainstream choices like Python, C, C++ and Java (cf. Tiobe Index)—are they worth using? Certainly it depends a lot on the planned use: is it a one-off small project, or […]

The post Choosing a Computer Language for a Project first appeared on John D. Cook.

On greedy algorithms and rodeo clowns

2024-04-22 21:16:23

This weekend I ran across a blog post The Rodeo Clown Theory of Personal Development. The title comes from a hypothetical example of a goal you don’t know how to achieve: becoming a rodeo clown. Let’s say you decide you want to be a rodeo clown. And let’s say you’re me and you have no […]

The post On greedy algorithms and rodeo clowns first appeared on John D. Cook.

Finding strings in binary files

2024-04-20 23:54:28

There’s a little program called strings that searches for what appear to be strings inside binary file. I’ll refer to it as strings(1) to distinguish the program name from the common English word strings. [1] What does strings(1) consider to be a string? By default it is a sequence of four or more bytes that […]

The post Finding strings in binary files first appeared on John D. Cook.

Extract text from a PDF

2024-04-20 20:31:59

Arshad Khan left a comment on my post on the less and more utilities saying “on ubuntu if I do less on a pdf file, it shows me the text contents of the pdf.” Apparently this is an undocumented feature of GNU less. It works, but I don’t see anything about it in the man […]

The post Extract text from a PDF first appeared on John D. Cook.

Length of a general Archimedean spiral

2024-04-20 07:58:15

This post ties together the previous three posts. In this post, I said that an Archimedean spiral has the polar equation r = b θ1/n and applied this here to rolls of carpet. When n = 1, the length of the spiral for θ running from 0 to T is approximately ½ bT² with the […]

The post Length of a general Archimedean spiral first appeared on John D. Cook.

How big will a carpet be when you roll or unroll it?

2024-04-18 21:52:57

If you know the dimensions of a carpet, what will the dimensions be when you roll it up into a cylinder? If you know the dimensions of a rolled-up carpet, what will the dimensions be when you unroll it? This post answers both questions. Flexible carpet: solid cylinder The edge of a rolled-up carpet can […]

The post How big will a carpet be when you roll or unroll it? first appeared on John D. Cook.

Approximating a spiral by rings

2024-04-17 22:19:31

An Archimedean spiral has the polar equation r = b θ1/n This post will look at the case n = 1. I may look at more general values of n in a future post. (Update: See here.) The case n = 1 is the simplest case, and it’s the case I needed for the client […]

The post Approximating a spiral by rings first appeared on John D. Cook.

Hypergeometric function of a large negative argument

2024-04-17 09:00:07

It’s occasionally necessary to evaluate a hypergeometric function at a large negative argument. I was working on a project today that involved evaluating F(a, b; c; z) where z is a large negative number. The hypergeometric function F(a, b; c; z) is defined by a power series in z whose coefficients are functions of a, […]

The post Hypergeometric function of a large negative argument first appeared on John D. Cook.

More is less

2024-04-16 19:40:35

When I first started using Unix, I used a program called “more” to read files. The name makes sense because each time you press the space bar, more will show you more of your file, one screen at a time. Now everyone uses less, and more is all but forgotten. Daniel Halbert wrote more in […]

The post More is less first appeared on John D. Cook.

Precise answers to useless questions

2024-04-12 20:25:05

I recently ran across a tweet from Allen Downey saying So much of 20th century statistics was just a waste of time, computing precise answers to useless questions. He’s right. I taught mathematical statistics at GSBS [1, 2] several times, and each time I taught it I became more aware of how pointless some of […]

The post Precise answers to useless questions first appeared on John D. Cook.

Pairs in poker

2024-04-11 10:38:24

An article by Y. L. Cheung [1] gives reasons why poker is usually played with five cards. The author gives several reasons, but here I’ll just look at one reason: pairs don’t act like you might expect if you have more than five cards. In five-card poker, the more pairs the better. Better here means […]

The post Pairs in poker first appeared on John D. Cook.

Solar system means

2024-04-10 22:40:27

Yesterday I stumbled on the fact that the size of Jupiter is roughly the geometric mean between the sizes of Earth and the Sun. That’s not too surprising: in some sense (i.e. on a logarithmic scale) Jupiter is the middle sized object in our solar system. What I find more surprising is that a systematic […]

The post Solar system means first appeared on John D. Cook.

Earth : Jupiter :: Jupiter : Sun

2024-04-10 01:50:06

The size of Jupiter is approximately the geometric mean of the sizes of Sun and Earth. In terms of radii, The ratio on the left equals 9.95 and the ratio on the left equals 10.98. The subscripts are the astronomical symbols for the Sun (☉, U+2609), Jupiter (♃, U+2643), and Earth (, U+1F728). I produced […]

The post Earth : Jupiter :: Jupiter : Sun first appeared on John D. Cook.

Gravity on Jupiter

2024-04-09 20:57:14

I was listening to the latest episode of the Space Rocket History podcast. The show includes some audio from a documentary on Pioneer 11 that mentioned that a man would weigh 500 pounds on Jupiter. My immediate thought was “Is that all?! Is this ‘man’ a 100 pound boy?” The documentary was correct and my […]

The post Gravity on Jupiter first appeared on John D. Cook.

Are guidance documents laws?

2024-04-06 07:48:05

Are guidance documents laws? No, but they can have legal significance. The people who generate regulatory guidance documents are not legislators. Legislators delegate to agencies to make rules, and agencies delegate to other organizations to make guidelines. For example [1], Even HHS, which has express cybersecurity rulemaking authority under the Health Insurance Portability and Accountability […]

The post Are guidance documents laws? first appeared on John D. Cook.

More Laguerre images

2024-04-02 11:10:27

A week or two ago I wrote about Laguerre’s root-finding method and made some associated images. This post gives a couple more examples. Laguerre’s method is very robust in the sense that it is likely to converge to a root, regardless of the starting point. However, it may be difficult to predict which root the […]

The post More Laguerre images first appeared on John D. Cook.

A Bayesian approach to proving you’re human

2024-03-28 22:47:00

I set up a GitHub account for a new employee this morning and spent a ridiculous amount of time proving that I’m human. The captcha was to listen to three audio clips at a time and say which one contains bird sounds. This is a really clever test, because humans can tell the difference between […]

The post A Bayesian approach to proving you’re human first appeared on John D. Cook.

Antenna length: Another rule of 72

2024-03-27 22:33:15

The famous Rule of 72 says that to find out how many years it takes an investment to double in value, divide 72 by the annual percentage rate. I’ll come back to that in a little bit. This morning I read a really good article, Fifty Things you can do with a Software Defined Radio. […]

The post Antenna length: Another rule of 72 first appeared on John D. Cook.

Hallucinations of AI Science Models

2024-03-26 23:35:48

AlphaFold 2, FourCastNet and CorrDiff are exciting. AI-driven autonomous labs are going to be a big deal [1]. Science codes now use AI and machine learning to make scientific discoveries on the world’s most powerful computers [2]. It’s common practice for scientists to ask questions about the validity, reliability and accuracy of the mathematical and […]

The post Hallucinations of AI Science Models first appeared on John D. Cook.

Double super factorial

2024-03-25 19:30:27

I saw someone point out recently that 10! = 7! × 5! × 3! × 1! Are there more examples like this? What would you call the pattern on the right? I don’t think there’s a standard name, but here’s why I think it should be called double super factorial or super double factorial. Super […]

The post Double super factorial first appeared on John D. Cook.